package com.funsport.controller.mobile;

import com.funsport.common.Result;
import com.funsport.dto.request.SubmitFeedbackRequest;
import com.funsport.security.SecurityUtils;
import com.funsport.service.IUserFeedbackService;
import com.funsport.service.WechatSecurityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 移动端用户反馈Controller
 *
 * @author Fun-Sport Team
 */
@Slf4j
@Tag(name = "用户反馈", description = "用户反馈相关接口")
@RestController
@RequestMapping("/mobile/feedback")
@RequiredArgsConstructor
public class MobileFeedbackController {
    
    private final IUserFeedbackService feedbackService;
    private final WechatSecurityService securityService;
    
    /**
     * 提交反馈
     */
    @Operation(summary = "提交反馈")
    @PostMapping("/submit")
    public Result<Void> submitFeedback(@Valid @RequestBody SubmitFeedbackRequest request) {
        Long userId = SecurityUtils.getCurrentUserId();
        log.info("用户 {} 提交反馈", userId);
        
        // 检测内容安全
        if (!securityService.checkText(request.getContent())) {
            log.warn("反馈内容包含违规信息: userId={}", userId);
            return Result.error("反馈内容包含违规信息，请修改后重试");
        }
        
        // 提交反馈
        feedbackService.submitFeedback(userId, request);
        
        return Result.success();
    }
}

